using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SpoonCore2.Message;
using SpoonCore2.Client;

namespace SpoonCore2.Service.Lock
{
	class LockMessage : AbstractMessage
	{
		public enum LockType : byte { Request, Release }
		public enum MessageType : byte { Request, Response }

		private LockType _lockType = LockType.Request;
		private MessageType _messageType = MessageType.Request;
		private SpoonIdentifier _requestId = new SpoonIdentifier();
		private SpoonIdentifier _serviceId;
		private SpoonIdentifier _id;

		public LockMessage()
		{
		}

		public LockMessage(SpoonIdentifier serviceId, SpoonIdentifier id)
		{
			_serviceId = serviceId;
			_id = id;
		}

		public LockType Lock
		{
			get { return _lockType; }
			set { _lockType = value; }
		}

		public MessageType Message
		{
			get { return _messageType; }
			set { _messageType = value; }
		}

		public SpoonIdentifier RequestId
		{
			get { return _requestId; }
			set { _requestId = value; }
		}

		public SpoonIdentifier ServiceId
		{
			get { return _serviceId; }
			set { _serviceId = value; }
		}

		public SpoonIdentifier Id
		{
			get { return _id; }
			set { _id = value; }
		}

		public override void GetBytes(BinaryWriter bw)
		{
			bw.Write((byte)Lock);
			bw.Write((byte)Message);
			bw.Write(RequestId.GetBytes());
			bw.Write(ServiceId.GetBytes());
			bw.Write(Id.GetBytes());
		}

		public override void SetBytes(IService service, BinaryReader br)
		{
			Lock = (LockType)br.ReadByte();
			Message = (MessageType)br.ReadByte();
			RequestId = new SpoonIdentifier(br);
			ServiceId = new SpoonIdentifier(br);
			Id = new SpoonIdentifier(br);
		}
	}
}
